﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 书易.DAL;
using 书易.Model;

namespace 书易.WEB
{
    public partial class flow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rep_GWC.DataSource = TradeDal.SelectYHSP(1);
                rep_GWC.DataBind();
            }
        }


        protected void LinkButton1_Click1(object sender, EventArgs e)
        {

        }

        protected void rep_GWC_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

           // Literal lit_price = e.Item.FindControl("lit_price") as Literal;
            // Trade t = e.Item.DataItem as Trade;

            //lit_price.Text = (t.BPrice * t.BCount) + "元";


        }
        protected void rep_GWC_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "sc")
            {
                Response.Redirect("ShanCSP.aspx?id=" + e.CommandArgument + "&URL=" + Server.UrlEncode(Request.Url.ToString()));
            }
        }

        protected void Unnamed1_TextChanged(object sender, EventArgs e)
        {
            
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < rep_GWC.Items.Count; i++){
                TextBox txt_count=rep_GWC.Items[i].FindControl("txt_count") as TextBox;
                int count = Convert.ToInt32(txt_count.Text);
                int BID = Convert.ToInt32(txt_count.Attributes["BID"]);
                int Bcount=  BookDal.SelectSumCount(BID);
                if (Bcount < count)
                {
                    ClientScript.RegisterStartupScript(GetType(),"","alert('书籍库存不足！')",true);
                    return;
                }
            }
            
            for (int i = 0; i < rep_GWC.Items.Count; i++)
            {
                TextBox txt_count=rep_GWC.Items[i].FindControl("txt_count") as TextBox;
                int TID = Convert.ToInt32(txt_count.Attributes["TID"]);
                int count = Convert.ToInt32(txt_count.Text);
                TradeDal.updateCount(TID, count);
            }
            Response.Redirect("flow.aspx");
        }
    }
}